<%@page import="com.surelution.projects.crm.NoGasTypeCategory"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="main"/>
<resource:dateChooser />
<g:set var="entityName" value="${message(code: 'noGasList.label', default: 'NoGasList')}" />
<g:javascript library="jquery"/>
<link rel="stylesheet" href="${resource(dir:'css',file:'defaultTheme.css')}" />
<script type="text/javascript" src="${resource(dir:'js/jquery',file:'jquery.fixedheadertable.min.js')}"></script>
<script type="text/javascript" src="${resource(dir:'js/jquery',file:'jquery.printElement.min.js')}"></script>
<script type="text/javascript" src="${resource(dir:'js/datechooser',file:'datechooser.js')}"></script>
<title><g:message code="default.report.label" args="[entityName]" /></title>
	<script type="text/javascript">
		$(document).ready(function() {
		   $("#simplePrint").click(function() {
		       printElem({leaveOpen: true, printMode: 'popup', overrideElementCSS: ["${resource(dir:'plugins/richui-0.8/css',file:'calendarmonthview.css')}","${resource(dir:'css',file:'main.css')}"]});
		   });
		   $('#myTable01').fixedHeaderTable({ footer: false, cloneHeadToFoot: false, autoShow: true });
		});
		function printElem(options){
		    $('#monthReport').printElement(options);
		};

	</script>
</head>

<body>
  	<div class="body">
          <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
            <span class="menuButton"><g:link class="create" action="compareReport">非油品销量同比环比查询</g:link></span>
          </div>
          
          <div>
        	<g:form action="report">
				<p style="font-size:16px;color:#000;margin:10px 0;">非油销量时间段查询</p>
        		选择日期：<richui:dateChooser locale="zh" name="startDay" format="yyyy-MM-dd" value="${startDay}"/>至<richui:dateChooser locale="zh" name="endDay" format="yyyy-MM-dd" value="${endDay}"/>
			             查询：<span class="menuButton" style="margin-right:5px;"><g:actionSubmit value="${message(code: 'default.button.report.label', default: 'report')}" action="report"/></span>
			    <span class="menuButton" style="margin-right:5px;"><g:actionSubmit value="${message(code: 'default.button.planReport.label', default: 'planReport')}" action="planReport"/></span><br>
    			选择片区：
				<g:each in="${com.surelution.projects.crm.StationArea.list()}" var="area">
	    			<g:checkBox id="stationArea.id_${area.id }" name="stationArea" value="${area.id }" checked="${stationArea!=[]?stationArea.contains(area.id):true}"/><label for="stationArea.id_${area.id }">${area.areaName}</label>&nbsp;
    			</g:each>
   			    <span class="menuButton"><g:actionSubmit value="${message(code: 'default.button.export.label', default: 'Export')}" action="reportExport"/></span>
			    <input type="button" value="打印报表" id="simplePrint" />
			</g:form>
			<g:if test="${flash.message}">
            	<div class="message">${flash.message}</div>
            </g:if>
        </div>
        <%
			def tDrink=0,tOil=0,tCarUse=0,tSmoke=0,tRetail=0,tAmount=0,tMaoLi=0,tMaoLiRate=0
			def NgSize =NoGasTypeCategory.list().size()
		 %>
        <div id="monthReport" style="height:620px;">
			<p style="font-size:16px;color:#000;margin:10px 0;">报表日期: ${startDay.format("yyyy.MM.dd")}到${endDay.format("yyyy.MM.dd") }</p>
       		<table id="myTable01">
       			<thead>
        		<tr>
        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;width:50px;">片区</td>
        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;width:100px;">加油站名</td>
           			<g:each in="${NoGasTypeCategory.list()}" var="l" >
        				<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">${l.name}(元)</td>
        			</g:each>
          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">总收入(元)</td>
          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">毛利(元)</td>
          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">毛利率%</td>
          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">排名</td>
    			</tr>
    			<tr class="even">
   					<td style="text-align:center;">合计</td>
   					<td> </td>
					<td style="text-align:center;"><div id="tDrink"></div></td>
					<td style="text-align:center;"><div id="tOil"></div></td>
					<td style="text-align:center;"><div id="tCarUse"></div></td>
					<td style="text-align:center;"><div id="tSmoke"></div></td>
					<td style="text-align:center;"><div id="tRetail"></div></td>
					<td style="text-align:center;"><div id="tAmount"></div></td>
					<td style="text-align:center;"><div id="tMaoLi"></div></td>
					<td style="text-align:center;">0</td>
   					<td style="text-align:center;"> 0</td>
   				</tr>
   				</thead>
   				<tbody>
   				<g:each in="${result}" var="r" status="i">
   				<%
					tDrink += r[2]
				   	tOil += r[3]
				   	tCarUse += r[4]
				   	tSmoke += r[5]
				   	tRetail += r[6]
				   	tAmount += r[NgSize + 2]
				   	tMaoLi += r[NgSize + 3]
				 %>
				<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
   					<td style="text-align:center;"> ${r[0].areaName}</td>
   					<td> ${r[1].shortName}</td>
						<td style="text-align:center;">${r[2]}</td>
						<td style="text-align:center;">${r[3]}</td>
						<td style="text-align:center;">${r[4]}</td>
						<td style="text-align:center;">${r[5]}</td>
						<td style="text-align:center;">${r[6]}</td>
   					<td style="text-align:center;">${r[NgSize + 2]}</td>
   					<td style="text-align:center;">${r[NgSize + 3]}</td>
   					<td style="text-align:center;">${r[NgSize + 4]}</td>
   					<td style="text-align:center;"> ${i+1}</td>
   				</tr>
   				</g:each>
   				</tbody>
          	</table>
        </div>
		<script type="text/javascript">
			document.getElementById("tDrink").innerHTML = '${(formatNumber(number:tDrink,maxFractionDigits:1)) }';
			document.getElementById("tOil").innerHTML = '${(formatNumber(number:tOil,maxFractionDigits:1)) }';
			document.getElementById("tCarUse").innerHTML = '${(formatNumber(number:tCarUse,maxFractionDigits:1)) }';
			document.getElementById("tSmoke").innerHTML = '${(formatNumber(number:tSmoke,maxFractionDigits:1)) }';
			document.getElementById("tRetail").innerHTML = '${(formatNumber(number:tRetail,maxFractionDigits:1)) }';
			document.getElementById("tAmount").innerHTML = '${(formatNumber(number:tAmount,maxFractionDigits:1)) }';
			document.getElementById("tMaoLi").innerHTML = '${(formatNumber(number:tMaoLi,maxFractionDigits:1)) }';
        </script>
  </div>
</body>
</html>